home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / RIncludes / MixedMode.r < prev    next >
Encoding:
Text File  |  1998-02-12  |  13.1 KB  |  420 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        MixedMode.r
  3.  
  4.      Contains:    Mixed Mode Manager Interfaces.
  5.  
  6.      Version:    Technology:    Mac OS 8
  7.                  Release:    Universal Interfaces 3.1
  8.  
  9.      Copyright:    © 1992-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18.  
  19. #ifndef __MIXEDMODE_R__
  20. #define __MIXEDMODE_R__
  21.  
  22. #ifndef __CONDITIONALMACROS_R__
  23. #include "ConditionalMacros.r"
  24. #endif
  25.  
  26. #define kRoutineDescriptorVersion         7
  27. #define _MixedModeMagic                 0xAAFE
  28. #define kCurrentMixedModeStateRecord     1
  29. #define kPascalStackBased                 0
  30. #define kCStackBased                     1
  31. #define kRegisterBased                     2
  32. #define kD0DispatchedPascalStackBased     8
  33. #define kD1DispatchedPascalStackBased     12
  34. #define kD0DispatchedCStackBased         9
  35. #define kStackDispatchedPascalStackBased  14
  36. #define kThinkCStackBased                 5
  37.  
  38. #define kM68kISA                         0
  39. #define kPowerPCISA                     1
  40.  
  41. #define kOld68kRTA                         0x00
  42. #define kPowerPCRTA                     0x00
  43. #define kCFM68kRTA                         0x10
  44.  
  45. #define kRegisterD0                     0
  46. #define kRegisterD1                     1
  47. #define kRegisterD2                     2
  48. #define kRegisterD3                     3
  49. #define kRegisterD4                     8
  50. #define kRegisterD5                     9
  51. #define kRegisterD6                     10
  52. #define kRegisterD7                     11
  53. #define kRegisterA0                     4
  54. #define kRegisterA1                     5
  55. #define kRegisterA2                     6
  56. #define kRegisterA3                     7
  57. #define kRegisterA4                     12
  58. #define kRegisterA5                     13
  59. #define kRegisterA6                     14                    /*  A7 is the same as the PowerPC SP  */
  60. #define kCCRegisterCBit                 16
  61. #define kCCRegisterVBit                 17
  62. #define kCCRegisterZBit                 18
  63. #define kCCRegisterNBit                 19
  64. #define kCCRegisterXBit                 20
  65.  
  66. #define kNoByteCode                     0
  67. #define kOneByteCode                     1
  68. #define kTwoByteCode                     2
  69. #define kFourByteCode                     3
  70.  
  71. #define kProcDescriptorIsAbsolute         0x00
  72. #define kProcDescriptorIsRelative         0x01
  73.  
  74. #define kFragmentIsPrepared             0x00
  75. #define kFragmentNeedsPreparing         0x02
  76.  
  77. #define kUseCurrentISA                     0x00
  78. #define kUseNativeISA                     0x04
  79.  
  80. #define kPassSelector                     0x00
  81. #define kDontPassSelector                 0x08
  82.  
  83. #define kRoutineIsNotDispatchedDefaultRoutine  0x00
  84. #define kRoutineIsDispatchedDefaultRoutine  0x10
  85.  
  86. #define kProcDescriptorIsProcPtr         0x00
  87. #define kProcDescriptorIsIndex             0x20
  88.  
  89. #define kSelectorsAreNotIndexable         0x00
  90. #define kSelectorsAreIndexable             0x01
  91.  
  92.                                                             /*  Calling Convention Offsets  */
  93. #define kCallingConventionWidth         4
  94. #define kCallingConventionPhase         0
  95. #define kCallingConventionMask             0x0F                /*  Result Offsets  */
  96. #define kResultSizeWidth                 2
  97. #define kResultSizePhase                 4
  98. #define kResultSizeMask                 0x30                /*  Parameter offsets & widths  */
  99. #define kStackParameterWidth             2
  100. #define kStackParameterPhase             6
  101. #define kStackParameterMask             0xFFFFFFC0            /*  Register Result Location offsets & widths  */
  102. #define kRegisterResultLocationWidth     5
  103. #define kRegisterResultLocationPhase     6                    /*  Register Parameter offsets & widths  */
  104. #define kRegisterParameterWidth         5
  105. #define kRegisterParameterPhase         11
  106. #define kRegisterParameterMask             0x7FFFF800
  107. #define kRegisterParameterSizePhase     0
  108. #define kRegisterParameterSizeWidth     2
  109. #define kRegisterParameterWhichPhase     2
  110. #define kRegisterParameterWhichWidth     3                    /*  Dispatched Stack Routine Selector offsets & widths  */
  111. #define kDispatchedSelectorSizeWidth     2
  112. #define kDispatchedSelectorSizePhase     6                    /*  Dispatched Stack Routine Parameter offsets  */
  113. #define kDispatchedParameterPhase         8                    /*  Special Case offsets & widths  */
  114. #define kSpecialCaseSelectorWidth         6
  115. #define kSpecialCaseSelectorPhase         4
  116. #define kSpecialCaseSelectorMask         0x03F0
  117.  
  118. #define kSpecialCase                     0x000F                /*  (CallingConventionType)  */
  119.                                                             /*  all of the special cases enumerated.  The selector field is 6 bits wide  */
  120. #define kSpecialCaseHighHook             0
  121. #define kSpecialCaseCaretHook             0                    /*  same as kSpecialCaseHighHook  */
  122. #define kSpecialCaseEOLHook             1
  123. #define kSpecialCaseWidthHook             2
  124. #define kSpecialCaseTextWidthHook         2                    /*  same as kSpecialCaseWidthHook  */
  125. #define kSpecialCaseNWidthHook             3
  126. #define kSpecialCaseDrawHook             4
  127. #define kSpecialCaseHitTestHook         5
  128. #define kSpecialCaseTEFindWord             6
  129. #define kSpecialCaseProtocolHandler     7
  130. #define kSpecialCaseSocketListener         8
  131. #define kSpecialCaseTERecalc             9
  132. #define kSpecialCaseTEDoText             10
  133. #define kSpecialCaseGNEFilterProc         11
  134. #define kSpecialCaseMBarHook             12
  135.  
  136. #define    GoMixedModeTrapType    unsigned hex integer
  137. #define    VersionType byte
  138. #define    SelectorsAreIndexableType boolean
  139. #define    Reserved1Type fill long
  140. #define    Reserved2Type fill byte
  141. #define    SelectorInfoType hex byte
  142. #define    RoutineCountType integer
  143. #define    ProcInfoType binary longint
  144. #define    Reserved3Type fill byte
  145. #define    ISAType byte
  146. #define    ProcDescriptorIsRelativeType boolean
  147. #define    FragmentNeedsPreparingType boolean
  148. #define    UseNativeISAType boolean
  149. #define    DontPassSelectorType boolean
  150. #define    RoutineIsDispatchedDefaultType boolean
  151. #define    ProcDescriptorType longint
  152. #define    Reserved4Type fill long
  153. #define    SelectorType longint
  154. /*
  155.     Use the 'rdes' template to define a “native resource” which 
  156.     starts with a routine descriptor. Such resources contain 
  157.     just PowerPC code. 
  158.     
  159.     Note that such resources can only be executed on PowerPC
  160.     machines. Executing them on a 68K machine will result 
  161.     in a crash.
  162.  
  163.     To create a “native resource”, use something like the following:
  164.     
  165. #include "MixedMode.r"
  166.  
  167. type 'BDef' as 'rdes';
  168.  
  169. resource 'BDef' (1) {
  170.     $1,                                        // ProcInfo
  171.     $$Resource("BDef.rsrc", 'pCod', 128)    // Specify name, type, and ID of resource
  172.                                             //   containing a pef container
  173. };
  174.  
  175. */
  176.  
  177. type 'rdes' { 
  178. Top:
  179.     /* Routine Descriptor */
  180.     GoMixedModeTrapType             = _MixedModeMagic;
  181.     VersionType                        = kRoutineDescriptorVersion;
  182.     fill bit [7];
  183.     SelectorsAreIndexableType        = FALSE;
  184.     Reserved1Type;
  185.     Reserved2Type;
  186.     SelectorInfoType                = 0;
  187.     RoutineCountType                = 0;
  188.  
  189.     /* Routine Record */
  190.     ProcInfoType;
  191.     Reserved3Type;
  192.     ISAType                            = kPowerPCISA;
  193.     fill bit [11];
  194.     RoutineIsDispatchedDefaultType     = FALSE;
  195.     DontPassSelectorType            = FALSE;
  196.     UseNativeISAType                = TRUE;
  197.     FragmentNeedsPreparingType        = TRUE;
  198.     ProcDescriptorIsRelativeType    = TRUE;
  199.     ProcDescriptorType                = (BeginningOfPowerPCCode-Top) / 8;
  200.     Reserved4Type;
  201.     SelectorType                    = 0;
  202.     Align LONG;
  203.  
  204. BeginningOfPowerPCCode:
  205.     hex string;                        // The PEF container starts here
  206. };
  207.  
  208.  
  209. /*
  210.     Use the 'fdes' template to define a “fat resource” which 
  211.     starts with a routine descriptor and contains both 68K and 
  212.     PowerPC code. 
  213.     
  214.     Note that such resources can only be executed on a machine
  215.     with MixedMode installed. To create “safe fat resources”
  216.     which will run on all machines, use the 'sdes' template
  217.     defined below.
  218.  
  219.     To create a “fat resource”, use something like the following:
  220.     
  221. #include "MixedMode.r"
  222.  
  223. type 'BDef' as 'fdes';
  224.  
  225. resource 'BDef' (1) {
  226.     $1,                                        // 68K ProcInfo
  227.     $1,                                        // PowerPC ProcInfo
  228.     $$Resource("BDef.rsrc", 'oCod', 128),    // Specify name, type, and ID of resource
  229.                                             //   containing 68k code
  230.     $$Resource("BDef.rsrc", 'pCod', 128)    // Specify name, type, and ID of resource
  231.                                             //   containing a pef container
  232. };
  233.  
  234. */
  235.  
  236. /*  Fat Routines  */
  237. type 'fdes' { 
  238. Top:
  239.     /* Routine Descriptor */
  240.     GoMixedModeTrapType             = _MixedModeMagic;
  241.     VersionType                        = kRoutineDescriptorVersion;
  242.     fill bit [7];
  243.     SelectorsAreIndexableType        = FALSE;
  244.     Reserved1Type;
  245.     Reserved2Type;
  246.     SelectorInfoType                = 0;
  247.     RoutineCountType                = 1;
  248.  
  249.     /* 68k Routine Record */
  250.     ProcInfoType;
  251.     Reserved3Type;
  252.     ISAType                            = kM68kISA;
  253.     fill bit [11];
  254.     RoutineIsDispatchedDefaultType     = FALSE;
  255.     DontPassSelectorType            = FALSE;
  256.     UseNativeISAType                = TRUE;
  257.     FragmentNeedsPreparingType        = FALSE;
  258.     ProcDescriptorIsRelativeType    = TRUE;
  259.     ProcDescriptorType                = (BeginningOf68KCode-Top) / 8;
  260.     Reserved4Type;
  261.     SelectorType                    = 0;
  262.  
  263.     /* PowerPC Routine Record 1 */
  264.     ProcInfoType;
  265.     Reserved3Type;
  266.     ISAType                            = kPowerPCISA;
  267.     fill bit [11];
  268.     RoutineIsDispatchedDefaultType     = FALSE;
  269.     DontPassSelectorType            = FALSE;
  270.     UseNativeISAType                = TRUE;
  271.     FragmentNeedsPreparingType        = TRUE;
  272.     ProcDescriptorIsRelativeType    = TRUE;
  273.     ProcDescriptorType                = (BeginningOfPowerPCCode-Top) / 8;
  274.     Reserved4Type;
  275.     SelectorType                    = 0;
  276.     Align LONG;
  277.  
  278. BeginningOf68kCode:
  279.     hex string;                // The code starts here
  280.     
  281.     Align LONG;
  282.  
  283. BeginningOfPowerPCCode:
  284.     hex string;                // The PEF container starts here
  285. };
  286.  
  287.  
  288. /*
  289.     Use the 'sdes' template to define a “safe fat resource” which 
  290.     contains both 68K and PowerPC code. A safe fat resource starts
  291.     with 68K code which is executed the first time the resource
  292.     is called. This code determines if MixedMode is present. If
  293.     so, a routine descriptor is moved to the beginning of the
  294.     resource. If not, a branch instruction to the 68K portion
  295.     of the code is placed at the beginning of the resource. 
  296.     Therefore, the first time the resource is executed, there 
  297.     is some overhead incurred. However, subsequent calls 
  298.     will be fast.
  299.     
  300.     Note: This template cannot currently be used for resources
  301.     containing code with register-based calling conventions
  302.     because the 68K code at the beginning of the resource
  303.     uses D0, A0, and A1.
  304.     
  305.     To create a “safe fat resource”, use something like the following:
  306.     
  307. #include "MixedMode.r"
  308.  
  309. type 'BDef' as 'sdes';
  310.  
  311. resource 'BDef' (1) {
  312.     $1,                                        // 68K ProcInfo
  313.     $1,                                        // PowerPC ProcInfo
  314.     $$Resource("BDef.rsrc", 'oCod', 128),    // Specify name, type, and ID of resource
  315.                                             //   containing 68k code
  316.     $$Resource("BDef.rsrc", 'pCod', 128)    // Specify name, type, and ID of resource
  317.                                             //   containing a pef container
  318. };
  319.  
  320. */
  321.  
  322. /*  Safe Fat Resources  */
  323. type 'sdes' { 
  324. Top:
  325.     hex string    = 
  326.         $"4E56 FFF0"      // SafeFatRsrc    LINK        A6, #-sysEnv1Size        ; Allocate a sysEnvRec
  327.         $"41EE FFF0"      //                LEA            -sysEnv1Size(A6), A0
  328.         $"7001"           //                MOVEQ        #1, D0                    ; On 6.X, Gestalt not be implemented...
  329.         $"A090"           //                _SysEnvirons    
  330.         $"4A40"           //                TST.W        D0
  331.         $"6640"           //                BNE.S        Install68K_60            ; if call fails, load up the 68K without FlushCache
  332.         $"0C68 0700 0004" //                CMPI        #$0700,systemVersion(A0)
  333.         $"6D38"           //                BLT.S        Install68K_60            ; if pre- 7.0, assume no cache        
  334.         $"303C A89F"      //                MOVE.W        #$A89F, D0                ; We have larger trap tables.  Is MixedMode installed?
  335.         $"A746"           //                _GetToolBoxTrapAddress                ; Leave _Unimplemented on the top of the stack...
  336.         $"2F08"           //                MOVE.L        A0, -(SP)                ; Unlk will clean this up
  337.         $"303C AAFE"      //                MOVE.W        #$AAFE, D0 
  338.         $"A746"           //                _GetToolBoxTrapAddress
  339.         $"B1D7"           //                CMPA.L        (SP), A0                
  340.         $"663E"           //                BNE.S        InstallPPCCode
  341.         $"41FA FFD4"      // Install68K_70    LEA            SafeFatRsrc, A0
  342.         $"30FC 6000"      //                MOVE.W        #$6000, (A0)+            ; Generate a BRA instruction
  343.         $"43FA 0044"      //                LEA            FatRD, A1
  344.         $"2029 0014"      //                MOVE.L        20(A1), D0                ; Get 68K code offset
  345.         $"5580"           //                SUBQ.L        #2, D0
  346.         $"3080"           //                MOVE.W        D0, (A0)                ; Fill in the second word of the BRA
  347.         $"303C A198"      //                MOVE.W        #$A198, D0                 ; Is _HWPriv implemented?
  348.         $"A346"           //                _GetOSTrapAddress
  349.         $"B1D7"           //                CMPA.L        (SP), A0
  350.         $"4E5E"           //                UNLK        A6
  351.         $"67B6"           //                BEQ.S        SafeFatRsrc
  352.         $"7001 A198"      //                _FlushInstructionCache
  353.         $"60B0"           //                BRA.S        SafeFatRsrc
  354.         $"4E5E"           // Install68K_60    UNLK        A6                        ; Old machine, FlushCache not supported
  355.         $"41FA FFAC"      //                LEA            SafeFatRsrc, A0                        
  356.         $"30FC 6000"      //                MOVE.W        #$6000, (A0)+            ; Generate a BRA instruction
  357.         $"43FA 001C"      //                LEA            FatRD, A1
  358.         $"2029 0014"      //                MOVE.L        20(A1), D0                ; Get 68K code offset
  359.         $"5580"           //                SUBQ.L        #2, D0
  360.         $"3080"           //                MOVE.W        D0, (A0)                ; Fill in the second word of the BRA
  361.         $"6098"           //                BRA.S        SafeFatRsrc
  362.         $"4E5E"           // InstallPPCCode    UNLK        A6
  363.         $"43FA FF94"      //                LEA            SafeFatRsrc, A1
  364.         $"41FA 0008"      //                LEA            FatRD, A0
  365.         $"7034"           //                MOVE.L        #52, D0
  366.         $"A02E"           //                _BlockMove                            ; Move R.D. to top of rsrc
  367.         $"6088";          //                BRA.S        SafeFatRsrc
  368.                           // FatRD    
  369.  
  370.     /* Routine Descriptor */
  371.     GoMixedModeTrapType             = _MixedModeMagic;
  372.     VersionType                        = kRoutineDescriptorVersion;
  373.     fill bit [7];
  374.     SelectorsAreIndexableType        = FALSE;
  375.     Reserved1Type;
  376.     Reserved2Type;
  377.     SelectorInfoType                = 0;
  378.     RoutineCountType                = 1;
  379.  
  380.     /* Routine Record */
  381.     ProcInfoType;
  382.     Reserved3Type;
  383.     ISAType                            = kM68kISA;
  384.     fill bit [11];
  385.     RoutineIsDispatchedDefaultType     = FALSE;
  386.     DontPassSelectorType            = FALSE;
  387.     UseNativeISAType                = TRUE;
  388.     FragmentNeedsPreparingType        = FALSE;
  389.     ProcDescriptorIsRelativeType    = TRUE;
  390.     ProcDescriptorType                = (BeginningOf68KCode-Top) / 8;
  391.     Reserved4Type;
  392.     SelectorType                    = 0;
  393.  
  394.     /* PowerPC Routine Record 1 */
  395.     ProcInfoType;
  396.     Reserved3Type;
  397.     ISAType    = kPowerPCISA;
  398.     fill bit [11];
  399.     RoutineIsDispatchedDefaultType     = FALSE;
  400.     DontPassSelectorType             = FALSE;
  401.     UseNativeISAType                 = TRUE;
  402.     FragmentNeedsPreparingType        = TRUE;
  403.     ProcDescriptorIsRelativeType    = TRUE;
  404.     ProcDescriptorType                 = (BeginningOfPowerPCCode-Top) / 8;
  405.     Reserved4Type;
  406.     SelectorType                     = 0;
  407.     Align LONG;
  408.  
  409. BeginningOf68KCode:
  410.     hex string;        // The 68k code starts here
  411.  
  412.     Align LONG;
  413.  
  414. BeginningOfPowerPCCode:
  415.     hex string;        // The PEF container starts here
  416. };
  417.  
  418. #endif /* __MIXEDMODE_R__ */
  419.  
  420.